package org.pi.common.scripting

class ScalaTool {

	private def onScriptError(errorMessage:String):Unit = { println("PI-ERR: "+errorMessage); throw new Error(errorMessage); }
	private val scriptSettings = new scala.tools.nsc.GenericRunnerSettings( onScriptError(_) )
	scriptSettings.classpath.value = System.getProperty("java.class.path");
	resetInterpreter()
	
	def resetInterpreter() : Unit = {
		//TODO
	}
	
	def closeInterpreter() : Unit = {
		//TODO
	}
	
	def bindVariable(name: String, variable: AnyRef) : Unit = {
		//TODO
	}
	
	def interpretCode(code : String, args: Array[String]): Unit = {
		scala.tools.nsc.ScriptRunner.runCommand(scriptSettings, code, args.toList);
	}
	
	def interpretFile(filename: String, args: Array[String]): Unit = {
		val code = org.pi.common.text.TextTool.loadTextFromFile(filename)
		interpretCode(code, args)
	}
}

object ScalaTool extends ScalaTool {
}
